{% extends "www/cohorts/base.html" %}
{% block title %}Manage {{ course.title  }}{% endblock %}

{% block page_content %}
<h2>{{cohort.title}} <span class="badge badge-secondary">Cohort</span></h2>

<p>
  {% set stats = cohort.get_stats() %}

  {{ stats.subgroups }} Subgroups
  | {{ stats.mentors }} Mentors
  | {{ stats.students }} students
  | {{ stats.join_requests }} join requests
</p>

{% if is_mentor %}
<div class="alert alert-info">
  {% set sg = mentor.get_subgroup() %}
  <p>You are a mentor of <b>{{sg.title}}</b> subgroup.</p>
  <p><a href="{{sg.get_url()}}" class="btn btn-primary">Visit Your Subgroup &rarr;</a></p>
</div>
{% endif %}

<ul class="nav nav-tabs">
  {% set num_subgroups = cohort.get_subgroups() | length %}
  {{ render_navitem("Subgroups", "", page=page, count=num_subgroups) }}
  {% for p in cohort.get_pages(scope="Cohort") %}
    {{ render_navitem(p.title, p.slug, page=page) }}
  {% endfor %}
</ul>

<div class="my-5">
{% if not page %}
  {{ render_subgroups() }}
{% else %}
  {{ render_page(page) }}
{% endif %}
</div>

{% endblock %}

{% macro render_subgroups() %}
<ul class="list-group">
  {% for sg in cohort.get_subgroups(include_counts=True) %}
    <li class="list-group-item">
      <div>
        <a class="subgroup-title"
          style="font-weight: 700; color: inherit;"
          href="/courses/{{course.name}}/subgroups/{{cohort.slug}}/{{sg.slug}}"
          >{{sg.title}}</a>
        </div>
      <div style="font-size: 0.8em;">
        {{sg.num_mentors}} Mentors
        |
        {{sg.num_students}} Students
        |
        {{sg.num_join_requests}} Join Requests
      </div>
    </li>
  {% endfor %}
</ul>
{% endmacro %}

{% macro render_navitem(title, link, page, count=-1) %}
  <li class="nav-item">
    <a
      class="nav-link {{ 'active' if link==page }}"
      href="/courses/{{course.name}}/cohorts/{{cohort.slug}}/{{link}}"
    >{{title}}
    {% if count != -1 %}
      <span
        class="badge {{'badge-primary' if link==page else 'badge-secondary'}}"
      >{{count}}</span>
    {% endif %}
    </a>
  </li>
{% endmacro %}
